package com.doubi.controller.sysDic;//package com.gaoguo.controller;

import com.doubi.common.aspectj.annotation.SysLog;
import com.doubi.model.sys.TArea;
import com.doubi.service.AreaService;
import com.doubi.utils.DataUtil;
import com.doubi.vo.AppModel;
import com.doubi.vo.PageVo;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 区域 信息操作处理
 *
 * @author MrDoubi
 * @date 2019-05-30 10:22:49
 */
@Controller
@RequestMapping("area")
public class AreaController {

    @Autowired
    private AreaService areaService;

    /**
     * 功能描述：进入页面路径
     * @author   MrDoubi 2019-06-29 16:40
     * @param cityOid       市oid
     * @param model         model
     * @return              返回页面路径
     */
    @RequiresPermissions("area:view")
    @GetMapping("view")
    public String list(String cityOid, Model model) {
        model.addAttribute("cityOid",cityOid);
        return "web/area/view";
    }


    /**
     * 功能说明：查询区域分页列表
     * @author MrDoubi
     * @date 2019-05-30 10:22:49
     */
    @SysLog(title = "查询区域分页列表")
    @RequiresPermissions("area:page")
    @PostMapping("page")
    @ResponseBody
    public PageVo<TArea> getPage(PageVo<TArea> page, TArea area) {
        return areaService.getPage(page, area);
    }



    /**
     * 功能说明：查询区域列表
     * @author MrDoubi
     * @date 2019-05-30 10:22:49
     */
    @RequiresPermissions("area:list")
    @PostMapping("list")
    @ResponseBody
    public List<TArea> getList(TArea area) {
        return areaService.getList(area);
    }

    /**
     * 功能说明：修改区域
     * @author MrDoubi
     * @date 2019-05-30 10:22:49
     */
    @RequiresPermissions(value = {"area:edit", "area:add"}, logical = Logical.OR)
    @GetMapping("edit")
    public String edit(TArea area, Model model) {
        if (DataUtil.isNotEmpty(area.getAreaOid())) {
            area = areaService.getById(area.getAreaOid());
        }
        model.addAttribute("bean", area);
        return "web/area/edit";
    }

    /**
     * 功能说明：保存区域
     * @author MrDoubi
     * @date 2019-05-30 10:22:49
     */
    @SysLog(title = "保存区域")
    @RequiresPermissions("area:saveOrUpdate")
    @PostMapping("saveOrUpdate")
    @ResponseBody
    public AppModel saveOrUpdate(TArea area) {
        return areaService.saveOrUpdateBean(area);
    }

    /**
     * 功能说明：删除区域
     * @author MrDoubi
     * @date 2019-05-30 10:22:49
     */
    @SysLog(title = "删除区域")
    @RequiresPermissions("area:delBean")
    @PostMapping("delBean")
    @ResponseBody
    public AppModel delBean(TArea area) {
        return areaService.delBean(area);
    }

    /**
     * 功能说明：功能说明：区域状态更新 接口
     * @author  MrDoubi 2019-01-10 15:14:33
     * @param area bean
     * @return model
     */
    @SysLog(title = "区域状态更新 接口")
    @RequiresPermissions("area:updateStatus")
    @PostMapping("updateStatus")
    @ResponseBody
    public AppModel updateStatus(TArea area){
        return areaService.updateStatus(area);
    }
}
